package com.bgs.eat.commodity.controller;

import com.bgs.eat.commodity.entity.CommodityEntity;
import com.bgs.eat.commodity.service.CommodityService;
import com.bgs.eat.config.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName CommodityOrderController
 * @Description TODO
 * @Author lzy
 * @Date 2022/10/19 14:08
 **/
@RestController
@RequestMapping("/commodity")
@CrossOrigin
public class CommodityController {

    @Autowired
    CommodityService commodityService;

    /**
    * @Description 根据id商家商品（门户商家版）
    * @Author lzy
    * @Date 2022/10/25 9:02
    * @Return com.bgs.eat.config.CommonResult
    * @param id
    */
    @GetMapping("/putawayCommodity")
    public CommonResult putawayCommodity(Integer id) {
        return commodityService.putawayCommodity(id);
    }

    /**
    * @Description 根据店铺id获取下架商品
    * @Author lzy
    * @Date 2022/10/25 8:56
    * @Return com.bgs.eat.config.CommonResult
    * @param shopId
    */
    @GetMapping("/getSoldOutCommodityByShopId")
    public CommonResult getSoldOutCommodityByShopId(Integer shopId) {
        return commodityService.getSoldOutCommodityByShopId(shopId);
    }

    /**
    * @Description 下架商品（门户商家版）
    * @Author lzy
    * @Date 2022/10/25 8:42
    * @Return com.bgs.eat.config.CommonResult
    * @param id
    */
    @GetMapping("/soldOutCommodity")
    public CommonResult soldOutCommodity(Integer id){
        return commodityService.soldOutCommodity(id);
    }

    /**
    * @Description 新增 商品信息（门户商家版）
    * @Author lzy
    * @Date 2022/10/21 8:54
    * @Return com.bgs.eat.config.CommonResult
    * @param file
    * @param commodityEntity
    */
    @RequestMapping("/saveCommodity")
    public CommonResult saveCommodity(MultipartFile file, CommodityEntity commodityEntity){
        return commodityService.saveCommodity(file,commodityEntity);
    }

    /**
    * @Description 根据 店铺id获取 商品信息（门户商家版）
    * @Author lzy
    * @Date 2022/10/21 14:02
    * @Return com.bgs.eat.config.CommonResult
    * @param shopId
     * @param typeId
    */
    @GetMapping("/getCommodityListByShopIdAndTypeId")
    public CommonResult getCommodityListByShopIdAndTypeId(Integer shopId, Integer typeId) {
        return commodityService.getCommodityListByShopIdAndTypeId(shopId,typeId);
    }

    /**
    * @Description 根据id获取商品信息（门户商家版）
    * @Author lzy
    * @Date 2022/10/24 15:00
    * @Return com.bgs.eat.config.CommonResult
    * @param id
    */
    @GetMapping("/getCommodityListById")
    public CommonResult getCommodityListById(Integer id) {
        return commodityService.getCommodityListById(id);
    }

    /**
    * @Description 修改商品信息（门户商家版）
    * @Author lzy
    * @Date 2022/10/24 19:44
    * @Return com.bgs.eat.config.CommonResult
    * @param file
    * @param commodityEntity
    */
    @PostMapping("/editCommodity")
    public CommonResult editCommodity(MultipartFile file, CommodityEntity commodityEntity){
        return commodityService.editCommodity(file, commodityEntity);
    }

    /**
     * @Description 修改商品信息 无图片（门户商家版）
     * @Author lzy
     * @Date 2022/10/25 10:14
     * @Return com.bgs.eat.config.CommonResult
     * @param commodityEntity
     */
    @PostMapping("/editCommodityNoImage")
    public CommonResult editCommodityNoImage(@RequestBody CommodityEntity commodityEntity){
        return commodityService.editCommodityNoImage(commodityEntity);
    }

    /**
    * @Description 根据id删除商品信息（门户商家版）
    * @Author lzy
    * @Date 2022/10/25 13:48
    * @Return com.bgs.eat.config.CommonResult
    * @param id
    */
    @DeleteMapping("/deleteCommodityById")
    public CommonResult deleteCommodityById(@RequestBody Integer id) {
        return commodityService.deleteCommodityById(id);
    }

    /**
    * @Description 修改 商品总数（门户商家版）
    * @Author lzy
    * @Date 2022/10/27 8:53
    * @Return com.bgs.eat.config.CommonResult
    * @param id
    * @param mode 0减商品总数(sum) 1加商品总数(sum)
    */
    @GetMapping("editCommoditySumById")
    public CommonResult editCommoditySumById (Integer id, Integer mode) {
        return commodityService.editCommoditySumById(id,mode);
    }

    /**
    * @Description 根据店铺id获取商品信息列表（门户用户版）
    * @Author lzy
    * @Date 2022/10/27 11:18
    * @Return com.bgs.eat.config.CommonResult
    * @param shopId
    */
    @GetMapping("/getCommodityListAllByShopId")
    public CommonResult getCommodityListAll(Integer shopId){
        return commodityService.getCommodityListAllByShopId(shopId);
    }

    @GetMapping("/test")
    public CommonResult test(){
        return null;
    }


}
